<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <link rel="stylesheet" type="text/css" href="css/base.css"/>
    <link rel="stylesheet" type="text/css" href="css/register.css"/>
    <script src="js/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="main">
    <div class="title">REGISTER</div>
    <div class="mid">
        <div class="lf">
            <ul>
                <li>
                    用户名：
                </li>
                <li>
                    密码：
                </li>
                <li>
                    确认密码：
                </li>
                <li>
                    性别：
                </li>
                <li>
                    电话：
                </li>
                <li>
                    年龄：
                </li>
                <li>
                    姓名：
                </li>
                <li>
                    学号：
                </li>
            </ul>
        </div>
        <div class="lr">
            <ul>
                <li>
                    <input type="text" id="account" class="ipt-current">
                </li>
                <li>
                    <input type="password" id="pwd" class="ipt-current">
                </li>
                <li>
                    <input type="password" id="new-pwd" class="ipt-current">
                </li>
                <li id="sex">
                    <div class="man">
                        <input type="radio" name="radio" value="1" checked="checked" class="ipt-current">男
                    </div>
                    <div class="woman">
                        <input type="radio" name="radio" value="0" class="ipt-current">女
                    </div>
                </li>
                <li><input type="tel" id="tel" required="required" class="ipt-current">
                </li>
                <li>
                    <input type="text" id="age" class="ipt-current">
                </li>
                <li>
                    <input type="text" id="name" class="ipt-current">
                </li>
                <li>
                    <input type="text" id="no" class="ipt-current">
                </li>
            </ul>
        </div>
    </div>
    <div class="dl">
        <button type="button" id="btn">注册</button>
    </div>
    <div class="lo">
        已有账号,去<a href="login.html">登录</a>
    </div>
</div>
</body>
<script>
    $(document).ready(function (){
        $(".ipt-current").each(function (){
            $(this).blur(function (){
                if(this.value == ""){
                    $(this).addClass("input-none")
                    alert("不能为空！")
                }else{
                    $(this).removeClass("input-none")
                }
            })
        })
        $("#btn").click(function (){
            if($("#account").val() == "" || $("#pwd").val() == "" || $("#new-pwd").val() == "" || $("#tel").val() == "" || $("#age").val() == "" || $("#name").val() == "" || $("#no").val() == ""){

            }else{
                let sex = $("#sex").val();
                if(sex == "男"){
                    sex = 0;
                }else{
                    sex = 1;
                }
                if($("#pwd").val() == $("#new-pwd").val()){
                    $.ajax({
                        type:"get",
                        url:"http://120.76.130.104:9000/user/register",
                        data:{
                            account:$("#account").val(),
                            password:$("#pwd").val(),
                            sex:sex,
                            age:$("#age").val(),
                            name:$("#name").val(),
                            gardeNumber:$("#no").val()
                        },
                        success:function (data,text,http){
                            alert(data.msg)
                            if (data.code == "001"){
                                window.location = "login.html"
                            }else{
                                alert("注册失败！")
                            }
                        }
                    })
                }else{
                    alert("两次输入密码不一致，请重新输入！")
                }
            }

        })
    })
</script>
</html>